package com.yili.oa.service.impl;

import com.yili.oa.dao.ExtractsRecordMapper;
import com.yili.oa.entity.ExtractsRecordSearch;
import com.yili.oa.entity.SearchBase;
import com.yili.oa.models.ExtractsRecord;
import com.yili.oa.models.ExtractsRecordExample;
import com.yili.oa.service.ExtractsRecordService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(value = "transactionManager")
public class ExtractsRecordServiceImpl implements ExtractsRecordService {

    @Autowired
    ExtractsRecordMapper mapper;

    @Override
    public List<ExtractsRecord> get(ExtractsRecordSearch searchBase) {
        ExtractsRecordExample example = new ExtractsRecordExample();
        ExtractsRecordExample.Criteria criteria = example.createCriteria();
        if(searchBase.getRecordId()!=null){
            criteria.andIdEqualTo(searchBase.getRecordId());
        }
        if(searchBase.getRecordId()!=null){
            criteria.andUserIdEqualTo(searchBase.getUserId());
        }
        if(searchBase.getBeginDate()!=null){
            criteria.andCreateTimeGreaterThanOrEqualTo(searchBase.getBeginDate());
        }
        if(searchBase.getEndDate()!=null){
            criteria.andCreateTimeLessThanOrEqualTo(searchBase.getBeginDate());
        }
        if(searchBase.getStatus()!=null){
            criteria.andStatusEqualTo(searchBase.getStatus());
        }
        return mapper.selectByExample(example);
    }

    @Override
    public ExtractsRecord add(ExtractsRecord extractsRecord) {
        mapper.insert(extractsRecord);
        return extractsRecord;
    }

    @Override
    public ExtractsRecord update(ExtractsRecord extractsRecord) {
        mapper.updateByPrimaryKeySelective(extractsRecord);
        return extractsRecord;
    }

    @Override
    public void delete(List<Long> ids) {
        for (Long id : ids) {
            mapper.deleteByPrimaryKey(id);
        }
    }
}
